<template>
	<main-container>
		<!-- 工具栏 -->
		<div class="hx-table-toolbar">
			<div></div>
			<right-toolbar :searchBtn="false" :refreshBtn="true" @search="showSearch = !showSearch" @refresh="initPage"></right-toolbar>
		</div>
		<!-- 列表 -->
		<el-table v-loading="loading" :data="tableData" border>
			<el-table-column prop="userInfo" label="用户信息">
				<template #default="scope">
					<el-link type="primary">{{ scope.row.userInfo.nickName }}({{ scope.row.userInfo.phone }})</el-link>
				</template>
			</el-table-column>
			<el-table-column prop="frozenAmount" label="冻结中佣金" />
			<el-table-column prop="totalAmount" label="累计总佣金" />
			<el-table-column prop="totalWithdrawal" label="累计提现佣金" />
			<el-table-column prop="createTime" label="创建时间" />
		</el-table>
		<!-- 分页 -->
		<pagination
			v-model:total="page.total"
			v-model:currentPage="page.currentPage"
			v-model:pageSize="page.pageSize"
			@changePage="initPage"
		></pagination>
	</main-container>
</template>
<script lang="ts">
import { defineComponent, ref, reactive, toRefs } from 'vue';
import { getPage } from '/@/api/mall/distributionuser';
export default defineComponent({
	setup() {
		const data = reactive({
			queryParams: {},
			page: {
				total: 0, // 总页数
				currentPage: 1, // 当前页数
				pageSize: 10, // 每页显示多少条
			},
			tableData: [],
		});
		const showSearch = ref(true);
		const loading = ref(false);

		const initPage = async () => {
			loading.value = true;
			let params = {
				current: data.page.currentPage,
				size: data.page.pageSize,
			};
			await getPage(Object.assign(params, data.queryParams))
				.then((response) => {
					data.tableData = response.data.data.records;
					data.page.total = response.data.data.total;
					loading.value = false;
				})
				.catch(() => {
					loading.value = false;
				});
		};
		/**
		 * 重置搜索表单
		 */
		const resetQuery = () => {
			data.queryParams = {};
		};

		initPage();
		return {
			loading,
			showSearch,
			initPage,
			resetQuery,
			...toRefs(data),
		};
	},
});
</script>
